<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>学院列表-学生选课后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/weadmin.css">
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../../static/js/jquery-1.11.1.min.js"></script>
    <script src="../../static/js/common.js" charset="utf-8"></script>
</head>

<body>
<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">日志管理</a>
        <a><cite>日志列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="weadmin-body">
    <div class="layui-row" id="search">
        <form class="layui-form layui-col-md12 we-search">
            <!--<div class="layui-inline">-->
                <!--<input class="layui-input" placeholder="开始日" name="start" id="start">-->
            <!--</div>-->
            <!--<div class="layui-inline">-->
                <!--<input class="layui-input" placeholder="截止日" name="end" id="end">-->
            <!--</div>-->

            <div class="layui-inline">
                <input type="text" name="username" placeholder="请输入用户名称" autocomplete="off" class="layui-input">
            </div>
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <div class="weadmin-block">
        <!--<button class="layui-btn" onclick="WeAdminShow('添加学院','./add.html')"><i class="layui-icon"></i>添加</button>-->
    </div>

    <table class="layui-hide" id="departmentList" lay-filter="departmentbar"></table>
    <script type="text/html" id="departmentOpBar">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

</div>
<script>
    layui.extend({
        admin: '{/}../../static/js/admin'
    });

    layui.use(['table', 'jquery', 'form', 'admin'], function () {
        var table = layui.table,
            $ = layui.jquery,
            form = layui.form,
            admin = layui.admin;
        $.ajax({
            url: "http://localhost:9001/access_log",
            type: "GET",
            contentType: "application/json;charset=utf-8",
            success: function (json) {
                if (json.result == "") {
                    json.result = {};
                } else {
                    table.render({
                        elem: '#departmentList',
                        cellMinWidth: 80,
                        cols: [
                            [{
                                field: 'id', title: 'ID',width: 80
                            },{
                                field: 'username', title: '用户',width:80
                            },{
                                field: 'ip', title: 'ip',width:80
                            },{
                                field: 'url', title: '请求url',width:80
                            },{
                                field: 'createTimeStr', title: '请求时间',sort:true
                            }, {
                                field: 'method', title: '请求方法',
                            }, {
                                field: 'params', title: '参数',
                            },{
                                field: 'operation', title: '操作',width:120
                            },{
                                field: 'time', title: '请求时长',width:100
                            },{
                                field: 'operate',
                                title: '操作',
                                align: 'center',
                                toolbar: '#departmentOpBar',
                                unresize: true
                                ,width:100
                            }]
                        ],
                        data: json.result,
                        event: true,
                        page: true
                    });

                    //监听工具条
                    table.on('tool(departmentbar)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'detail') {

                            layer.msg('ID：' + data.id + ' 的查看操作');

                        } else if (obj.event === 'del') {
                            layer.confirm('真的删除行么', function (index) {
                                $.ajax({
                                    url: "http://localhost:9001/access_log/" + data.id,
                                    type: "DELETE",
                                    contentType: "application/json;charset=utf-8",
                                    success: function (json) {
                                        obj.del();
                                        layer.close(index);
                                        layer.alert("删除成功")
                                    }
                                });


                            });
                        } else if (obj.event === 'edit') {
                            layer.alert('编辑行：<br>' + JSON.stringify(data))
                        }
                    });
                }
            }
        });
        /*
         *数据表格中form表单元素是动态插入,所以需要更新渲染下
         * http://www.layui.com/doc/modules/form.html#render
         * */
        $(function () {
            form.render();
        });
    });

</script>
</body>

</html>